﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Collections.ObjectModel;
using System.Windows.Input;
using Resn.WhuPub.BLL;
using System.Linq;

namespace Resn.WhuPub.WPFClientUI
{
        /// <summary>
        /// SearchCategoryWindow.xaml 的交互逻辑
        /// </summary>
        public partial class SearchTravelFlowWindow
        {
                private readonly GlobalManager _gm = GlobalManager.Instance;

                public SearchTravelFlowWindow()
                {
                        InitializeComponent();
                }

                private void Window_Loaded(object sender, RoutedEventArgs e)
                {
                        _gm.Contact = null;

                        LayoutRoot.DataContext = _gm;
                }

                private void Window_OnMouseDown(object sender, MouseButtonEventArgs e)
                {
                        if (e.ChangedButton == MouseButton.Left)
                        {
                                this.DragMove();
                        }
                }

                private void AcceptButton_Click(object sender, RoutedEventArgs e)
                {
                        try
                        {
                                var result = _gm.LoginEmployee.TravelFlows;

                                if (_gm.Contact != null)
                                {
                                        result = result.Where(i => i.IsContainsContact(_gm.Contact)).ToList();
                                }

                                _gm.TravelFlows = new ObservableCollection<TravelFlow>(result);
                        }
                        catch (Exception ex)
                        {
                                MessageBox.Show(ex.Message);
                                return;
                        }

                        finally
                        {
                        }

                        Close();
                }

                
        }
}